
package com.oahc.magicdefender.manager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.oahc.magicdefender.util.MDConfig;

public class Arrow extends Image {

    private float initY;

    public Arrow(TextureRegion region) {
        super(region);
    }

    float K;

    /**
     * 设置箭移动直线的斜率
     * 
     * @param K
     */
    public void setK(float K) {
        this.K = K;
        Gdx.app.log("MD", "K=" + K);
        initY = getY();
    }

    @Override
    public void act(float delta) {
        // TODO Auto-generated method stub
        super.act(delta);

        this.setX(getX() + MDConfig.exchangeX(MDConfig.ARROW_SPEED));
        this.setY(getX() * K + initY);
        
        if(isOutOfScreen()){
            setVisible(false);
        }
    }

    private boolean isOutOfScreen(){
        if(getX()<0||getX()>Gdx.graphics.getWidth()){
            return true;
        }
        
        if(getY()<0|| getY()>Gdx.graphics.getHeight()){
            return true;
        }
        
        return false;
    }
}
